<?php

/**
 * home actions.
 *
 * @package    M2M
 * @subpackage home
 * @author     Saul Santiago
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class homeActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
//    $this->forward('default', 'module');
  }

  public function executeDatadump(sfWebRequest $request)
  {
    $this->forward404Unless($table = $request->getParameter('table'));

//    $params['from'] = ($request->getPostParameter('date_from') != '') ? $request->getPostParameter('date_from') : '';
//    $params['to'] = ($request->getPostParameter('date_to') != '') ? $request->getPostParameter('date_to') : '';
//    $params['ref_number'] = ($request->getPostParameter('ref_number') != '') ? $request->getPostParameter('ref_number') : '';
//    $params['first_name'] = ($request->getPostParameter('first_name') != '') ? $request->getPostParameter('first_name') : '';
//    $params['last_name'] = ($request->getPostParameter('last_name') != '') ? $request->getPostParameter('last_name') : '';
//    $params['status'] = ($request->getPostParameter('status') != '') ? $request->getPostParameter('status') : '';

    switch($table) {
      case 'booking':
        $dumpType = 'Bookings';
        break;
      case 'presentation':
        $dumpType = 'PresentationDownloads';
        break;
    }

    $data = Doctrine_Core::getTable($dumpType)->getApplicationData();

    if(!empty($data)) {

      header('Content-Type: text/plain');
      header('Content-Disposition: attachment;filename="'.$dumpType.'.xls"');
      header('Cache-Control: max-age=0');

      foreach($data as $k=>$i) {
        unset($i['updated_at']);
        if($k == 0) {
            foreach(array_keys($i) as $field) {
              echo $field."\t";
            }
            echo "\r\n";
        }
        foreach($i as $key=>$val) {
          echo $val."\t";
        }
        echo "\r\n";
      }
    }
    else {
      echo "No data to dump!";
    }
    exit();

  }

}
